import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DownloadFolderDemo {

	public static void main(String[] args) {
		String urlPath = "http://124.16.8.16:82/resource_app/uploadFiles/resources/1303443851468/";
		try {
			URL url = new URL(urlPath);
			InputStream is = url.openStream();
			URLConnection connection = url.openConnection();
			InputStreamReader isr = new InputStreamReader(is);
			int line = 0;
			char[] buffer = new char[1024];
			StringBuffer stringBuffer = new StringBuffer();
			while ((line = isr.read(buffer)) != -1) {
				// System.out.println(String.valueOf(buffer, 0, line));
				stringBuffer.append(buffer, 0, line);
				buffer = new char[1024];
			}
			System.out.println(stringBuffer.toString());
			String html = stringBuffer.toString();
			Pattern pattern = Pattern.compile("<a.+href=\'.*\n.*\'>.*\n.*</a>");
			Matcher matcher = pattern.matcher(html);
			String matchString = "";
			while (matcher.find()) {
				// System.out.println(matcher.group());
				matchString = matcher.group();
			}
			matchString.replaceAll("\n", "");
			System.out.println(matchString);
			is.close();
			isr.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
